#ifndef DOWNLOADDIALOG_H
#define DOWNLOADDIALOG_H

#include <QDialog>
#include <QTimer>

#include <thread>
#include <vector>
#include <atomic>
#include <mutex>

QT_BEGIN_NAMESPACE
namespace Ui { class DownloadDialog; }
QT_END_NAMESPACE

enum DownLoadStatus
{
    DownloadOver,
    Downloading,
    WaitDownload,
};

class QStringListModel;
class QStandardItemModel;

class DownloadDialog : public QDialog
{
    Q_OBJECT

public:
    DownloadDialog(QWidget *parent = nullptr);
    ~DownloadDialog();

private slots:
    void on_BtnSetIndexPath_clicked();
    void on_btnSetCurrentPath_clicked();
    void on_BtnParaFile_clicked();
    void on_btnSetWgetPath_clicked();
    void on_btnStop_clicked();
    void on_BtnMergerToFile_clicked();

    void UpdateTimes();
public:
    bool DownloadFileList();
    bool DownloadFile(QString Path);
    bool InitPath(QString IndexPath="");
    bool InitList(QString Path);
    bool GetTask(QString&);
    bool CleanDir(QString,
                  QStringList TmpFileSub = {".0", ".1", ".2", ".3", ".4", ".5", ".6", ".7", ".8", ".9"});

    bool MergerFile(QString path, QString outName, int timeOut = 2*60*60*1000);

private:
    Ui::DownloadDialog *ui;

    QString m_BasePath = "";
    QString m_FileName = "";
    QStandardItemModel *m_pDownloadOver = nullptr;
    QStandardItemModel *m_pWaiteDownload = nullptr;

    std::mutex m_Mutex;
    QTimer* m_Timer = nullptr;
    std::atomic_bool m_Stop;
    std::atomic_int m_ThreadS;
};
#endif // DOWNLOADDIALOG_H
